package com.herb.phoenix.models;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.badlogic.gdx.utils.Array;

public class PhoenixLevel
{
	private int level;
	private Array<Fleet> fleets;
	private int fleetIndex;
	
	public PhoenixLevel(int level)
	{
		this.level = level;
		fleetIndex = 0;
		fleets = new Array<Fleet>();
	}
	
	public PhoenixLevel(JSONObject jsonObject) throws JSONException
	{
		this.level = jsonObject.getInt("level");
		fleetIndex = 0;
		fleets = new Array<Fleet>();
		
		JSONArray jsonArray = jsonObject.getJSONArray("fleets");
		
		for(int i=0;i<jsonArray.length();i++)
		{
			fleets.add(new Fleet(jsonArray.getJSONObject(i)));
		}
	}

	public static PhoenixLevel getDemoLevel(int level)
	{
		PhoenixLevel demoLevel = new PhoenixLevel(level);
		//demoLevel.fleets.add(Fleet.createDemoFleet4());
		//demoLevel.fleets.add(Fleet.createDemoFleet1());
		//demoLevel.fleets.add(Fleet.createDemoFleet2());
		//demoLevel.fleets.add(Fleet.createDemoFleet3());
		return demoLevel;
	}

	public int getLevel()
	{
		return level;
	}

	public void setLevel(int level)
	{
		this.level = level;
	}
	
	public Fleet getNextFleet()
	{
		Fleet nextFleet = fleets.get(fleetIndex);
		fleetIndex++;
		return nextFleet;
	}
	
	public boolean isOnLastFleet()
	{
		return fleetIndex==fleets.size;
	}
}
